package com.clas.liu.myapplication.network;

import android.support.v4.util.ArrayMap;

import com.google.gson.Gson;

import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.RequestBody;

/**
 * 用于创建post方法的okthhp的Request实例
 * Created by liu on 2019/2/25.
 */

public class JsonPostRequest {
    private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
    private String mUrl;  //请求地址
    private ArrayMap<String,String> mRequestParam; //请求参数

    public JsonPostRequest(String mUrl, ArrayMap<String, String> mRequestParam) {
        this.mUrl = mUrl;
        this.mRequestParam = mRequestParam;
    }

    /**
     * post方法的Request请求创建
     * @return Request实例
     */
    public Request getRequest(){
        RequestBody body = RequestBody.create(JSON,new Gson().toJson(mRequestParam));
        return new Request.Builder().url(mUrl).post(body).tag("tag").build();
    }
}
